package com.byxy.managerial.action;

import java.util.List;

import javax.annotation.Resource;

import com.byxy.managerial.entity.Department;
import com.byxy.managerial.service.DepartmentService;
import com.byxy.managerial.service.StaffService;
import com.byxy.managerial.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 获取管理员数,部门数,员工人数已经其他数据
 * 
 * @author muxiangling
 *
 */
public class GetNumberAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private Integer staffTotal;// 员工总数
	private Integer departTotal;// 部门总数
	private Integer userTotal;// 管理员总数
	private String departName;//// 最多人数部门名称
	private Integer maxDepartNum;// 最多人数部门人数
	private Integer maxNum10 = 0;// 人数10或以上的部门数量
	private Integer minNum10 = 0;// 人数小于10的部门数量

	@Resource
	private DepartmentService departmentService;
	@Resource
	private StaffService staffService;
	@Resource
	private UserService userService;

	@Override
	public String execute() throws Exception {
		staffTotal = staffService.countTotal();
		departTotal = departmentService.countTotal();
		userTotal = userService.countTotal();
		List<Department> departments = departmentService.find();
		int i = 0;
		for (Department d : departments) {
			System.out.println("我是"+d.getDname()+d.getStaff().size());
			if (d.getStaff().size() <= i) {// 循环计算出最多人数的部门
				i = d.getStaff().size();
			} else {
				maxDepartNum = d.getStaff().size();
				departName = d.getDname();
			}
			if (d.getStaff().size() >= 10) {// 循环计算出大于或少于10人的部门数量
				maxNum10++;
			} else {
				minNum10++;
			}
		}
		return SUCCESS;
	}

	public Integer getStaffTotal() {
		return staffTotal;
	}

	public void setStaffTotal(Integer staffTotal) {
		this.staffTotal = staffTotal;
	}

	public Integer getDepartTotal() {
		return departTotal;
	}

	public void setDepartTotal(Integer departTotal) {
		this.departTotal = departTotal;
	}

	public Integer getUserTotal() {
		return userTotal;
	}

	public void setUserTotal(Integer userTotal) {
		this.userTotal = userTotal;
	}

	public String getDepartName() {
		return departName;
	}

	public void setDepartName(String departName) {
		this.departName = departName;
	}

	public Integer getMaxDepartNum() {
		return maxDepartNum;
	}

	public void setMaxDepartNum(Integer maxDepartNum) {
		this.maxDepartNum = maxDepartNum;
	}

	public Integer getMaxNum10() {
		return maxNum10;
	}

	public void setMaxNum10(Integer maxNum10) {
		this.maxNum10 = maxNum10;
	}

	public Integer getMinNum10() {
		return minNum10;
	}

	public void setMinNum10(Integer minNum10) {
		this.minNum10 = minNum10;
	}

}
